<?php

class User extends AppModel {

    var $name = 'User';
    var $useTable = 'user';
    var $hasMany = array('UserCredit' => array(
            'fields' => array('UserCredit.id', 'UserCredit.credit'),
            'foreignKey' => 'user_id'
        ),
        'Subject' => array(
            'fields' => array('Subject.id', 'Subject.subject'),
            'foreignKey' => 'user_id'
            ),
        'SubjectRate'=>array(
            'fields'=>'SubjectRate.subject_id',
            'foreignKey'=>'user_id'
        ));
    var $hasOne = array('UserProfile');
    //var $actsAs = array('Acl' => array('type' => 'requester'));
    var $validate = array(
        'username' => array(
            'isUnique' => array(
                'rule' => 'isUnique',
                'message' => 'User with this name already exists. Choose another'
            ),
            'minLength' => array(
                'rule' => array('minLength', 1),
                'message' => 'Please specify Login name'
            )
        ),
        'email' => array(
            'rule' => array('email'),
            'message' => 'Invalid email address'
        )/* ,
          'ip'=>array(
          'rule'=>array('isUnique'),
          'message'=>'There can only be one account per IP.'
          ) */,
        'UserProfile.screenname' => array(
            'rule' => 'isUnique',
            'message' => 'Screen Name not available choose another'
        )
    );

    function parentNode() {
        if (!$this->id && empty($this->data)) {
            return null;
        }
        if (isset($this->data['User']['group_id'])) {
            $groupId = $this->data['User']['group_id'];
        } else {
            $groupId = $this->field('group_id');
        }
        if (!$groupId) {
            return null;
        } else {
            return array('Group' => array('id' => $groupId));
        }
    }

    

   

}

?>